package com.hyf.okhttp3demo.support;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2017/12/12.
 */

public class MainListAdapter extends BaseAdapter {
    private List<Item> datas;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public MainListAdapter(List<Item> datas, Context context) {
        this.datas = datas;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Item item = datas.get(position);
        TextView textView = (TextView) mLayoutInflater.inflate(android.R.layout.simple_list_item_1, null);
        textView.setText(item.getTitle());
        textView.setOnClickListener(item.getClickListener());
        return textView;
    }
}
